import { Behaviour } from "./gameengine";
import { getPlatform } from "./platform";

export class JsonBehaviour extends Behaviour {

    json:string = "";

    protected onStart() {
        this.loadJson();
        // this.updateJson();
    }
    protected onUpdate(advancedTime: number) {
        
    }

    loadJson(){
        const filepath = 'assets/scene/landing.scene.json';
        // const filepath = fs.readdirSync(dir).map(filename => dir + "/" + filename);

        getPlatform().loadText(filepath, (text) => {
            this.json = JSON.parse(text);
            console.log(this.json);
        })
 
    }

    updateJson(){
        const xhr = new XMLHttpRequest();
        // xhr.onload = () => {
        //     callback(xhr.responseText);
        // }
        xhr.open("set", this.json);
        xhr.send();
        console.log(xhr);
    }

    saveJson() {
        const content = JSON.stringify(this.json, null, '\t');
        //         fs.writeFileSync(filepath, conent, "utf-8");
    }
}